package com.zeny.xdclass.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zeny.xdclass.common.ResponseResult;
import com.zeny.xdclass.domain.Video;
import com.zeny.xdclass.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName VideoController
 * @Description TODO
 * @Author zeny
 */
@RestController
@RequestMapping("/api/v1/video")
@Api(tags = "视频模块")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @ApiOperation(value = "分页查询视频列表")
    @GetMapping("/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "size", defaultValue = "10", required = true)
    })
    public ResponseResult list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                               @RequestParam(value = "size", defaultValue = "10") Integer size) {
        PageHelper.startPage(page, size);
        List<Video> list = videoService.findAll();
        PageInfo<Video> pageInfo = new PageInfo<>(list);
        return ResponseResult.ok().data(pageInfo);
    }

    @ApiOperation(value = "根据ID查找视频")
    @GetMapping("/findById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "视频ID", defaultValue = "1", required = true)
    })
    public ResponseResult findById(@RequestParam(value = "id", required = true) Integer id) {
        return ResponseResult.ok().data(videoService.findById(id));
    }


}
